//
//  MyCollectionVc.swift
//  Venus
//
//  Created by apple on 2018/8/26.
//  Copyright © 2018年 zhaowang. All rights reserved.
//  我的收藏   话题 ：POST /topic/queryCollectionTopicList
// 机构 ： /institution/queryCollectionInstitutionList

import UIKit


/// 我的收藏
class MyCollectionVc: BaseViewController {
    
    /// 分段式图
    fileprivate lazy var segVC :UISegmentedControl = {
        let seg = UISegmentedControl.init(items: ["机构收藏", "话题收藏"])
        seg.tintColor = UIColor.init(r: 23, g: 187, b: 254)
        seg.selectedSegmentIndex = 0
        seg.addTarget(self, action: #selector(clickSegVC(sender:)), for: .valueChanged)
        return seg
    }()
    
    /// 容纳子控制器的view
    fileprivate lazy var contentView = UIView()
    
    /// 显示的控制器
    fileprivate lazy var showVc : MyCollectionInstitutionVC = MyCollectionInstitutionVC()
    
    /// 收藏的话题
    fileprivate lazy var topicVC : MyCollectionTopicVC = MyCollectionTopicVC()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.bringSubviewToFront(self.navgationBar)
        self.title = "我的收藏"
        self.view.backgroundColor = UIColor.white
        setupUI()
    }
}


extension MyCollectionVc {
    func setupUI() {
        view.addSubview(segVC)
        view.addSubview(contentView)
        
        segVC.snp.makeConstraints { (make) in
            make.left.right.equalTo(view)
            make.top.equalTo(LayoutCommon.navHeight + 10)
            make.height.equalTo(45)
        }
        
        contentView.snp.makeConstraints { (make) in
            make.top.equalTo(segVC.snp.bottom).offset(5)
            make.left.right.equalTo(view)
            if #available(iOS 11.0, *) {
                make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom)
            } else {
                make.bottom.equalTo(view.snp.bottom)
            }
        }
        
        self.addChild(showVc)
        self.addChild(topicVC)
        contentView.addSubview(showVc.view)
        contentView.addSubview(topicVC.view)
        showVc.view.frame = contentView.bounds
        topicVC.view.frame = contentView.bounds
        topicVC.view.isHidden = true
    }
    
    @objc func clickSegVC(sender:UISegmentedControl) {
        showVc.view.isHidden = sender.selectedSegmentIndex == 1
        topicVC.view.isHidden = sender.selectedSegmentIndex == 0
    }
    
}



